﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTSBLL;
using TTSModel;
using TTS;
public partial class Repair_RRH_RRH_T0002000 : System.Web.UI.Page
{
    private Assemble assemble_T0002000;
    private AssembleItem assembleItem_T0002000;
    private string message;
    private string sn { get { return ViewState["sn"].ToString(); } set { ViewState["sn"] = value; } }
    private const string storedProcedureName = "AssemblyT0002000_Delete";
    public Repair_RRH_RRH_T0002000()
    {
        assemble_T0002000 = new Assemble();
        assembleItem_T0002000 = new AssembleItem();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //sn = this.T0002000_Input.Text.Trim();
        this.T0002000_Input.Focus();
    }
    protected void Repair_Click(object sender, EventArgs e)
    {
       /* if (!string.IsNullOrEmpty(sn))
        {
            if (!assembleItem_T0002000.AssembleItem_SubSNAlreadyExist(sn))
            {
                if (assemble_T0002000.Assemble_SNAlreadyExist(sn))
                {
                    AssembleInfo ainfo = assemble_T0002000.Assemble_GetbySN(sn);

                    if (assembleItem_T0002000.AssembleItem_GetbyID(ainfo.ID).Count== 1)
                    {
                        assemble_T0002000.AssembleDeleteBySN(sn, storedProcedureName);
                        message = "装配关系解锁成功！";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                        this.T0002000_Input.Text = "";
                    }
                    else
                    {
                        message = "请先选择T0002040解锁链接进行解锁！";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                    }

                }
                else
                {
                    message = "该" + sn + "在数据库中不存在装配记录，请重新扫描正确的SN号！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                }
            }
            else
            {
                message = "请先解锁" + sn + "对应的主机！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
            }
        }
        else
        {
            message = "请确保输入框不能为空！";
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        }*/
        assemble_T0002000.AssembleDeleteBySN(sn, storedProcedureName);
        message = "装配关系解锁成功！";
        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        this.T0002000_Input.Text = "";
        this.Remove.Enabled = false;
    }
    protected void Return_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Repair/RRH/RRHRepairHtml.aspx");
    }
    protected void T0002000_Input_TextChanged(object sender, EventArgs e)
    {
        sn = this.T0002000_Input.Text.Trim();
        if (SNHelper.SNCheck(sn, "T0002040", out message))
        {
            if (!assembleItem_T0002000.AssembleItem_SubSNAlreadyExist(sn))
            {
                if (assemble_T0002000.Assemble_SNAlreadyExist(sn))
                {
                    AssembleInfo ainfo = assemble_T0002000.Assemble_GetbySN(sn);

                    if (assembleItem_T0002000.AssembleItem_GetbyID(ainfo.ID).Count == 1)
                    {
                        this.Remove.Enabled = true;
                        this.Remove.Focus();
                    }
                    else
                    {
                        message = "请先选择T0002040解锁链接进行解锁！";
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                        this.T0002000_Input.Text = "";
                    }

                }
                else
                {
                    message = "该" + sn + "在数据库中不存在装配记录，请重新扫描正确的SN号！";
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                    this.T0002000_Input.Text = "";
                }
            }
            else
            {
                message = "请先解锁" + sn + "对应的主机！";
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
                this.T0002000_Input.Text = "";
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(ClientScript.GetType(), "", "<script>alert('" + message + "');</script>");
        }
    }
}